-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Verifier] Require that dbg.declare variable is a ptr #134355
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
As far as I understand, the first operand of dbg_declare should be a pointer (inside a metadata wrapper). However, using a non-pointer is currently not rejected, and we have some tests that use non-pointer types. As far as I can tell, these tests either meant to use dbg_value or are just incorrect hand-crafted tests. Ran into this while trying to fix llvm#134008.
@llvm/pr-subscribers-llvm-ir @llvm/pr-subscribers-backend-x86 Author: Nikita Popov (nikic) ChangesAs far as I understand, the first operand of dbg_declare should be a pointer (inside a metadata wrapper). However, using a non-pointer is currently not rejected, and we have some tests that use non-pointer types. As far as I can tell, these tests either meant to use dbg_value or are just incorrect hand-crafted tests. Ran into this while trying to Full diff: https://github.com/llvm/llvm-project/pull/134355.diff 8 Files Affected:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM, I can't think of a reason we should allow non-ptrs there. Just an inline question around test changes. @SLTozer do you have any additional comments? (I'll let you hit the approve button)
%rand = tail call i64 @lrand48() #3 | ||
tail call void @llvm.dbg.declare(metadata i64 %rand, metadata !6, metadata !7), !dbg !8 | ||
tail call void @llvm.dbg.declare(metadata ptr %ptr, metadata !6, metadata !7), !dbg !8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this slightly changes the tested behaviour, because the new dbg.declare will get put in the MF side-table:
https://godbolt.org/z/bh6oEM55G
The old dbg.declare causes a DBG_INSTR_REF, whereas the new on gets stuffed into stack:
. I think this may be the case in a couple of other tests too. If you make %ptr
an argument instead of a local alloca it looks like a DBG_VALUE
is generated, which is closer to the output of the original test.
Since the test isn't checking for the debug instruction in the output, maybe it doesn't matter, but I'd personally err on the side of minimising the change in output. YMMV.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Principle SGTM, probably calls for a documentation update: this could be extremely minor just to stress the "new" requirement, updating the text for #dbg_declare
in SourceLevelDebugging.rst:'
- The first argument is an SSA value corresponding to a variable address, and is
+ The first argument is an SSA `ptr` value corresponding to a variable address, and is
llvm/lib/IR/Verifier.cpp
Outdated
if (DVR.isDbgDeclare()) | ||
CheckDI(VAM->getValue()->getType()->isPointerTy(), | ||
"location of #dbg_declare must be a pointer", &DVR, MD); | ||
} else if (auto *AL = dyn_cast<DIArgList>(MD)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit, since the if now uses braces the "else if" should as well.
@@ -55,8 +55,9 @@ end: ; preds = %body | |||
|
|||
define i64 @simulateWithDbgDeclare(<2 x i32> %a) local_unnamed_addr { | |||
entry: | |||
%ptr = alloca i32 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slightly awkward case here in that this might degrade the test quality... the intent here seems to be to test that the debug declare does not cause any changes to the code in the CHECK set below, so making it no longer use %rand
as an argument might interfere with that.
But otoh the test is non-specific; there's no description of how the debug declare might be expected to affect codegen, so I don't think I have a specific suggested change - you could add a store i64 %rand, ptr %ptr
, or expand the check to cover the generated code for %ptr
, but I also don't think it's a blocking issue if it stays as-is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, adding a store like that would affect the existing CHECK lines, so I'm not sure that's better...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'm not convinced there are any solid answers - the test is to check that "nothing bad happens" because of the presence of a dbg.declare, rather than checking for a specific defect, so it's not clear what properties would need to be maintained to keep the test valid. If there aren't any obvious solutions, I'm fine with the latest revision.
When salvaging debug info for #dbg_declare, do not perform salvage that changes the type of the value, i.e. bail out on cast instructions. This ensures that we don't run afoul of the verifier check in llvm#134355.
As far as I understand, the first operand of dbg_declare should be a pointer (inside a metadata wrapper). However, using a non-pointer is currently not rejected, and we have some tests that use non-pointer types. As far as I can tell, these tests either meant to use dbg_value or are just incorrect hand-crafted tests.
Ran into this while trying to
fix
#134008.